<?php

require_once 'PHPUnit/Extensions/ExceptionTestCase.php';
jClasses::inc('cube~Corner');

// Test of the limits of the Corner construct
class UTCorner extends PHPUnit_Extensions_ExceptionTestCase 
{
    public function testConstructOK() 
    {
        try 
        {
            $myCorner = new Corner(0);
        }
        catch (Exception $e) {$this->fail();}

        try 
        {
            $myCorner = new Corner(0, 0);
        }
        catch (Exception $e) {$this->fail();}

        try 
        {
            $myCorner = new Corner(0, 1);
        }
        catch (Exception $e) {$this->fail();}

        try 
        {
            $myCorner = new Corner(0, 2);
        }
        catch (Exception $e) {$this->fail();}
    }

    public function testConstructKO1() 
    {
        $this->setExpectedException('Exception');
        $myCorner = new Corner(Corner::MAX_CORNER + 1);
    }

    public function testConstructKO2() 
    {
        $this->setExpectedException('Exception');
        $myCorner = new Corner(-1);
    }

    public function testConstructKO3() 
    {
        $this->setExpectedException('Exception');
        $myCorner = new Corner("stupid param");
    }

    public function testConstructKO4() 
    {
        $this->setExpectedException('Exception');
        $myCorner = new Corner(0, -1);
    }

    public function testConstructKO5() 
    {
        $this->setExpectedException('Exception');
        $myCorner = new Corner(0, 3);
    }

    public function testTurnCW() 
    {
        $myCorner = new Corner(0, 0);
        $myCorner->turnCW();
        $this->assertTrue($myCorner->getOrientation() === 1);
        $myCorner->turnCW();
        $this->assertTrue($myCorner->getOrientation() === 2);
        $myCorner->turnCW();
        $this->assertTrue($myCorner->getOrientation() === 0);
    }

    public function testTurnCCW() 
    {
        $myCorner = new Corner(0, 0);
        $myCorner->turnCCW();
        $this->assertTrue($myCorner->getOrientation() === 2);
        $myCorner->turnCCW();
        $this->assertTrue($myCorner->getOrientation() === 1);
        $myCorner->turnCCW();
        $this->assertTrue($myCorner->getOrientation() === 0);
    }
}
?>
